package com.jeeplus.modules.web.wx;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.room.Room;
import com.jeeplus.common.utils.FileUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.ListPageUtil;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.number.RandomUtil;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.monitor.utils.Achieve;
import com.jeeplus.modules.monitor.utils.utils.CommonUtil;
import com.jeeplus.modules.web.entity.YJRoomUser;
import com.jeeplus.modules.web.entity.YjScoreRecord;
import com.jeeplus.modules.web.entity.wx.YsUser;
import com.jeeplus.modules.web.mapper.WxUserMapper;
import com.jeeplus.modules.web.mapper.YJRoomUserMapper;
import com.jeeplus.modules.web.mapper.YjScoreRecordMapper;
import com.jeeplus.modules.web.socket.UserMsgSocket;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HTTP;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;

import static com.jeeplus.modules.monitor.utils.Achieve.saveToImgByInputStream;

/**
 * Created by rongj on 2017/8/6.
 */
@Controller
@RequestMapping(value = "/wx/roomUser")
public class YjRoomUserController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(YjRoomUserController.class);
    private static String appid = Global.getConfig("appId");// 应用ID
    private static String appsecret = Global.getConfig("appSecret");// 应用密钥

    @Autowired
    WxUserMapper wxUserMapper;
    @Autowired
    YJRoomUserMapper yjRoomUserMapper;
    @Autowired
    YjScoreRecordMapper yjScoreRecordMapper;

    private List<YJRoomUser> pageList = new ArrayList<>();

    /**
     * 生成二维码
     *
     * @throws Exception
     */
    @RequestMapping(value = "createTwoDimensionCode")
    @ResponseBody
    public AjaxJson createTwoDimensionCode(String openId, String isCheck, HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        //SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();

        //1是检查
        if (isCheck.equals("1")) {
            //判断当前人员在不在房间内
            List<YJRoomUser> yjRoomList = yjRoomUserMapper.findIsOut("0", openId);
            if (yjRoomList.size() > 0) {
                j.setSuccess(true);
                j.setErrorCode("2");
                j.put("roomFlag", yjRoomList.get(0).getRoomFlag());
                j.put("roomNumber", yjRoomList.get(0).getRoomNum());
                j.put("unifiedScoring", yjRoomList.get(0).getUnifiedScoring());
                j.put("homeWnerId", yjRoomList.get(0).getHomeWnerId());
                j.setMsg("当前用户已在牌局中");
                return j;
            }
        }
        YsUser wxUserInfo = wxUserMapper.getWxUserInfo(openId);
        //User user = UserUtils.getUser();
        if (wxUserInfo == null) {
            j.setSuccess(true);
            j.setErrorCode("1");
            j.setMsg("用户不存在");
            return j;
        }


        //判断当前人员在不在房间内,如果在,直接返回该房间号对应的二维码
        List<YJRoomUser> yjRoomUserList = yjRoomUserMapper.findIsOut("0", openId);
        if (yjRoomUserList.size() > 0) {
            j.setSuccess(true);
            j.setMsg("二维码生成成功");
            j.put("filePath", request.getContextPath() + Global.USERFILES_BASE_URL
                    + yjRoomUserList.get(0).getRoomFlag() + "/paiqrcode/" + "room" + yjRoomUserList.get(0).getRoomNum() + ".png");
            j.put("roomFlag", yjRoomUserList.get(0).getRoomFlag());
            j.put("roomNumber", yjRoomUserList.get(0).getRoomNum());
            j.put("unifiedScoring", yjRoomUserList.get(0).getUnifiedScoring());
            j.put("homeWnerId", yjRoomUserList.get(0).getHomeWnerId());
            return j;
        }

        //房间唯一标识
        String roomFlag = Achieve.getUUIDString().substring(0, 12);
        //牌局号
        int roomNumber = RandomUtil.getRandomFive();

        //获取正在使用的牌局号
        List<String> numList = yjRoomUserMapper.findRooNumByIsOut("0");
        while (numList.contains(roomNumber)) {
            roomNumber = RandomUtil.getRandomFive();
        }

        String encoderContent = roomFlag + "@" + roomNumber;

        String token = CommonUtil.getToken(appid, appsecret).getAccessToken();
        Map<String, Object> params = new HashMap<>();
        params.put("scene", encoderContent);  //参数
        params.put("page", "pages/count/count"); //位置
        params.put("width", 430);

        CloseableHttpClient httpClient = HttpClientBuilder.create().build();

        HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + token);  // 接口
        httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
        String body = JSON.toJSONString(params);           //必须是json模式的 post
        try {
            StringEntity entity;
            entity = new StringEntity(body);

            entity.setContentType("image/png");

            httpPost.setEntity(entity);
            HttpResponse response;
            response = httpClient.execute(httpPost);
            InputStream inputStream = response.getEntity().getContent();
            String realPath = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL
                    + roomFlag + "/paiqrcode/";
            FileUtils.createDirectory(realPath);
            String name = "room" + roomNumber + ".png";
            saveToImgByInputStream(inputStream, realPath, name);  //保存图片

            j.put("filePath", request.getContextPath() + Global.USERFILES_BASE_URL
                    + roomFlag + "/paiqrcode/" + "room" + roomNumber + ".png");
            j.put("roomFlag", roomFlag);
            j.put("roomNumber", roomNumber);
            //这边生成统一记分还是各自记分
            j.put("unifiedScoring", request.getParameter("unifiedScoring"));
            j.put("homeWnerId", openId);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


		/*String realPath = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL
				+ wxUserInfo.getOpenid() + "/qrcode/";
		FileUtils.createDirectory(realPath);
		String name="room"+roomNumber+".png"; //encoderImgId此处二维码的图片名
		try {
			String filePath = realPath + name;  //存放路径
			TwoDimensionCode.encoderQRCode(encoderContent, filePath, "png");//执行生成二维码
			user.setQrCode(request.getContextPath()+Global.USERFILES_BASE_URL
					+ principal + "/qrcode/"+name);
			j.setSuccess(true);
			j.setMsg("二维码生成成功");
			j.put("filePath", request.getContextPath()+Global.USERFILES_BASE_URL
					+ wxUserInfo.getOpenid() + "/qrcode/"+name);
		} catch (Exception e) {

		}*/
        return j;
    }


    /**
     * 添加玩家
     * isInput 0 是扫码，1是填房间号
     *
     * @return
     */
    @RequestMapping("/addRoom")
    @ResponseBody
    public Map<String, Object> addRoom(String openId, String isInput, HttpServletRequest request) throws ParseException {
        String roomFlag = request.getParameter("roomFlag");
        String roomNumber = request.getParameter("roomNumber");
        String userName = request.getParameter("userName");
        String homeWnerId = request.getParameter("homeWnerId");
        String unifiedScoring = request.getParameter("unifiedScoring");
        Map<String, Object> map = new HashMap<String, Object>();
        if ("1".equals(isInput)) {
            List<YJRoomUser> user = yjRoomUserMapper.findFalgByNumber(roomNumber);
            if (user.size() > 0) {
                roomFlag = user.get(0).getRoomFlag();
            } else {
                map.put("success", true);
                map.put("errorCode", "2");
                map.put("msg", "房间号不存在！");
                return map;
            }
        }
        List<YJRoomUser> roomUserList = yjRoomUserMapper.findUserByFlagAndNum(roomNumber, roomFlag);
        if (roomUserList.size() > 0) {
            boolean bool = roomUserList.stream().anyMatch(a -> a.getIsOut().equals("0"));
            if (bool == false) {
                map.put("success", true);
                map.put("errorCode", "2");
                map.put("msg", "该房间已结束游戏！");
                return map;
            }
        }

        //判断当前人员在不在房间内
        List<YJRoomUser> yjRoomUserList = yjRoomUserMapper.findIsOut("0", openId);
        if (yjRoomUserList.size() > 0) {
            map.put("success", true);
            map.put("errorCode", "2");
            map.put("roomNumber", yjRoomUserList.get(0).getRoomNum());
            map.put("roomFlag", yjRoomUserList.get(0).getRoomFlag());
            map.put("msg", "当前用户已加入房间！");
            return map;
        }
        //获取用户信息
        //YsUser wxUserInfo = wxUserMapper.getWxUserInfo(openId);
        YJRoomUser yjRoomUser = new YJRoomUser();
        yjRoomUser.setRoomFlag(roomFlag);
        yjRoomUser.setRoomNum(roomNumber);
        yjRoomUser.setRoomUser(openId);
        yjRoomUser.setIsOut("0");
        yjRoomUser.setEndGamesCount("1");


        yjRoomUser.setUserName(userName);//用户名称
        yjRoomUser.setHomeWnerId(homeWnerId);//房主ID
        yjRoomUser.setUnifiedScoring(unifiedScoring);//统一记分

        Room.ROMM_TYEP_MAP.put(openId + roomNumber, userName);
        yjRoomUser.preInsert();
        List<YJRoomUser> user = yjRoomUserMapper.findUserByFlagAndNumAndOpenId(roomNumber, roomFlag, openId);
        if (user.size() > 0) {
            yjRoomUserMapper.updateIsOutByUser("0", openId, roomFlag);
        } else {
            List<YJRoomUser> userByFlagAndNum = null;
            if (yjRoomUserMapper.findUserByFlagAndNum(roomNumber, roomFlag).isEmpty()) {

                yjRoomUser.setHomeWnerId(openId);
            } else {
                userByFlagAndNum = yjRoomUserMapper.findUserByFlagAndNum(roomNumber, roomFlag);
                yjRoomUser.setHomeWnerId(userByFlagAndNum.get(0).getHomeWnerId());
                yjRoomUser.setUnifiedScoring(userByFlagAndNum.get(0).getUnifiedScoring());//统一记分

            }
            YsUser wxUserInfo = wxUserMapper.getWxUserInfo(openId);
            if (wxUserInfo != null && StrUtil.isNotEmpty(wxUserInfo.getUserName())) {
                yjRoomUser.setUserName(wxUserInfo.getUserName());
            } else {
                yjRoomUser.setUserName(userName);
            }
            yjRoomUserMapper.addRoomUser(yjRoomUser);
        }
        map.put("success", true);
        map.put("errorCode", "0");
        map.put("roomNumber", roomNumber);
        map.put("roomFlag", roomFlag);
        map.put("msg", "成功加入房间！");


        try {
            System.out.println("openId=" + openId + "--roomflag=" + roomFlag);
            final Map<String, Pair<String, UserMsgSocket>> row = UserMsgSocket.webSocketTable.column(roomFlag);
            String newOpenId = "";
            for (String key : row.keySet()) {
                System.out.println("已经存在的key==" + key);
                newOpenId = key;
                break;
            }
            if (!newOpenId.equals("")) {
                UserMsgSocket.webSocketTable.row(newOpenId).get(roomFlag).getValue1().sendMessage();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


        return map;
    }

    /**
     * 校验是否在房间内
     *
     * @return
     */
    @RequestMapping("/checkRoom")
    @ResponseBody
    public Map<String, Object> checkRoom(String openId) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        //判断当前人员在不在房间内
        List<YJRoomUser> yjRoomUserList = yjRoomUserMapper.findIsOut("0", openId);
        if (yjRoomUserList.size() > 0) {
            map.put("success", true);
            map.put("errorCode", "0");
            map.put("in_room", true);
            map.put("roomNumber", yjRoomUserList.get(0).getRoomNum());
            map.put("roomFlag", yjRoomUserList.get(0).getRoomFlag());
            map.put("homeWnerId", yjRoomUserList.get(0).getHomeWnerId());
            map.put("unifiedScoring", yjRoomUserList.get(0).getUnifiedScoring());
            map.put("msg", "当前用户已加入房间！");

        } else {
            map.put("success", true);
            map.put("errorCode", "0");
            map.put("in_room", false);
            map.put("roomNumber", "");
            map.put("roomFlag", "");
            map.put("msg", "当前用户不在房间内！");
        }
        return map;
    }


    /**
     * 结束战斗
     *
     * @return
     */
    @RequestMapping("/getOut")
    @ResponseBody
    public Map<String, Object> getOut(String openId, HttpServletRequest request) {
        String roomFlag = request.getParameter("roomFlag");
       /* String roomNumber = request.getParameter("roomNumber");
		String pageSize = request.getParameter("pageSize");*/
        Map<String, Object> map = new HashMap<String, Object>();
        yjRoomUserMapper.updateIsOutByUser("1", openId, roomFlag);
	/*	//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");



      List<YJRoomUser> recordList = new ArrayList<>();
		//局数
		List<YjScoreRecord> gameCountList = yjScoreRecordMapper.getCostTotal(roomFlag, roomNumber);
		for(YjScoreRecord record : gameCountList){
			YJRoomUser user = new YJRoomUser();
			user.setGamesCount(record.getGamesCount());
			List<YjScoreRecord> userList = yjScoreRecordMapper.findByGamesCount(roomFlag,roomNumber,record.getGamesCount());
			YjScoreRecord yjScoreRecord = yjScoreRecordMapper.getTotalScoreByCount(roomFlag,roomNumber,record.getGamesCount());
			user.setGamesTotal(yjScoreRecord.getGameCost());
			user.setList(userList);
			user.setCreateDate(userList.get(0).getCreateDate());
			recordList.add(user);
		}
		pageList = recordList;
		int a = recordList.size();
		int b = Integer.valueOf(pageSize);
		if(a%b == 0){
			map.put("pageCount",a/b);
		}else {
			map.put("pageCount",a/b+1);
		}
		map.put("rowCount",a);
		List<YJRoomUser> pagedList = new ArrayList<>();
		//进行分页
		if(recordList.size() > 0){
			ListPageUtil<YJRoomUser> listPageUtil = new ListPageUtil<YJRoomUser>(recordList,1, Integer.valueOf(pageSize));
			 pagedList = listPageUtil.getPagedList();
		}
		//房间总台费
		List<YjScoreRecord> costList = yjScoreRecordMapper.getCostTotalByRoom(roomFlag, roomNumber);
		//获取每个人总分
		List<YjScoreRecord> totalUserList = yjScoreRecordMapper.scoreTotal(roomFlag, roomNumber);
		for(YjScoreRecord record : totalUserList){
			YjScoreRecord winRateRecord = yjScoreRecordMapper.getWinRate(roomFlag,record.getRoomUser());
			record.setWinRate(winRateRecord.getWinRate());
		}

        List<YjScoreRecord> yjScoreRecordList = yjScoreRecordMapper.findGamesCount(roomFlag,openId);
		long dateTime;
		if(yjScoreRecordList.size() > 0 && yjScoreRecordList.get(0) != null){
			dateTime =  yjScoreRecordList.get(0).getCreateDate().getTime() - yjScoreRecordList.get(yjScoreRecordList.size() - 1).getCreateDate().getTime();
			dateTime = dateTime/(1000*60); //分钟
		}else{
			dateTime = 0;
		}

        map.put("totalTime",dateTime);
		map.put("totalScore",totalUserList);
		if(yjScoreRecordList.size() > 0){
			map.put("totalCount",yjScoreRecordList.get(0).getGamesCount());
		}else{
			map.put("totalCount",0);
		}
		if(costList.size() > 0 && costList.get(0) != null){

			map.put("totalCost",costList.get(0).getGameCost());
		}else{
			map.put("totalCost",0);
		}
		map.put("scoreList",pagedList);*/
        map.put("code", "200");
        map.put("success", true);
        return map;
    }


    /**
     * 点击查看更多
     *
     * @param pageSize
     * @param pageNo
     * @param roomFlag
     * @param roomNumber
     * @return
     */
    @RequestMapping("/lookByPage")
    @ResponseBody
    public Map<String, Object> lookByPage(String openId, String pageSize, String pageNo, String roomFlag, String roomNumber) {
        //局数
        List<YjScoreRecord> gameCount = yjScoreRecordMapper.findCount(roomFlag, roomNumber, (Integer.valueOf(pageNo) - 1) * Integer.valueOf(pageSize), Integer.valueOf(pageSize));
        List<YjScoreRecord> allGamesCount = yjScoreRecordMapper.findGamesCount(roomFlag, openId);
        //台费
        List<YjScoreRecord> gameCountList = yjScoreRecordMapper.getCostTotal(roomFlag, roomNumber, (Integer.valueOf(pageNo) - 1) * Integer.valueOf(pageSize), Integer.valueOf(pageSize));
        //总台费
        List<YjScoreRecord> costList = yjScoreRecordMapper.getCostTotalByRoom(roomFlag, roomNumber);

        YJRoomUser yjRoomUser = new YJRoomUser();
        yjRoomUser.setRoomUser("台费");


        if (costList.get(0) != null && costList.size() > 0) {
            yjRoomUser.setTotalScore(costList.get(0).getGameCost());
        } else {
            yjRoomUser.setTotalScore("0");
        }
        if (gameCountList != null && gameCountList.size() > 0) {
            yjRoomUser.setList(gameCount);
        } else {
            yjRoomUser.setList(new ArrayList<>());
        }

        //人员
        List<YJRoomUser> roomUserList = yjRoomUserMapper.findUserByFlagAndNum(roomNumber, roomFlag);

        for (int index = 0, length = roomUserList.size(); index < length; index++) {
            if (openId.equals(roomUserList.get(index).getRoomUser())) {
                YJRoomUser temp = roomUserList.get(0);
                roomUserList.set(0, roomUserList.get(index));
                roomUserList.set(index, temp);
            }
        }

        //获取每个人总分
        List<YjScoreRecord> totalUserList = yjScoreRecordMapper.scoreTotalS(roomFlag, roomNumber);
        for (YjScoreRecord record : totalUserList) {
            YjScoreRecord winRateRecord = yjScoreRecordMapper.getWinRate(roomFlag, record.getRoomUser());
            record.setWinRate(winRateRecord.getWinRate());
        }
        //局数
	/*List<YjScoreRecord> gameCountList = new ArrayList<>();
	if (scoreRecordList.size() > 0) {
		//取五条
		gameCountList = scoreRecordList.subList(0, Math.min(scoreRecordList.size(), 5));
	}*/
        for (YJRoomUser user : roomUserList) {
            if (totalUserList.size() > 0) {
                boolean bool = totalUserList.stream().anyMatch(a -> a.getRoomUser().equals(user.getRoomUser()));
                if (bool) {
                    for (YjScoreRecord record : totalUserList) {
                        if (record.getRoomUser().equals(user.getRoomUser())) {
                            user.setTotalScore(record.getScore());
                        }
                    }
                } else {
                    user.setTotalScore("0");
                }


                //获取每人所有局分数
                List<YjScoreRecord> userRecordList = yjScoreRecordMapper.getScoreDetailS(user.getRoomFlag(), user.getRoomNum(), user.getRoomUser(), "", (Integer.valueOf(pageNo) - 1) * Integer.valueOf(pageSize), Integer.valueOf(pageSize));

                List<YjScoreRecord> scoreUList = new ArrayList<>();
                for (YjScoreRecord record : gameCountList) {
                    //获取每人每局对应分数
                    List<YjScoreRecord> scoreUserList = userRecordList.stream().filter(userRecord -> userRecord.getGamesCount().equals(record.getGamesCount())).collect(Collectors.toList());

                    if (scoreUserList.size() > 0) {
                        scoreUList.add(scoreUserList.get(0));
                    } else {
                        YjScoreRecord recordw = new YjScoreRecord();
                        recordw.setRoomNum(user.getRoomNum());
                        recordw.setGamesCount(record.getGamesCount());
                        recordw.setScore("0");
                        recordw.setRoomUser(user.getRoomUser());
                        recordw.setRoomFlag(user.getRoomFlag());
                        scoreUList.add(recordw);
                    }
                }
                user.setList(scoreUList);

            } else {
                user.setList(new ArrayList<>());
                user.setTotalScore("0");
            }
            user.getList().stream().sorted(Comparator.comparing(YjScoreRecord::getGamesCount))
                    .collect(Collectors.toList());
        }
        //long mrenmeijuend = System.currentTimeMillis();
        //logger.info("getTotal--获取每个人每局分数总耗时："+(mrenmeijuend - mrenmeijustart) + "ms");
        Map<String, Object> map = new HashMap<String, Object>();

        int a = allGamesCount.size();
        int b = Integer.valueOf(pageSize);
        if (a % b == 0) {
            map.put("pageCount", a / b);
        } else {
            map.put("pageCount", a / b + 1);
        }
        map.put("totalCount", a);

        List<YjScoreRecord> yjScoreRecordList = yjScoreRecordMapper.findGamesCount(roomFlag, openId);
        long dateTime;
        if (yjScoreRecordList.size() > 0 && yjScoreRecordList.get(0) != null) {
            dateTime = yjScoreRecordList.get(0).getCreateDate().getTime() - yjScoreRecordList.get(yjScoreRecordList.size() - 1).getCreateDate().getTime();
            dateTime = dateTime / (1000 * 60); //分钟
        } else {
            dateTime = 0;
        }

        map.put("totalTime", dateTime);
        map.put("totalScore", totalUserList);


        if (costList.size() > 0 && costList.get(0) != null) {

            map.put("totalCost", costList.get(0).getGameCost());
        } else {
            map.put("totalCost", 0);
        }

        if (!roomUserList.isEmpty()) {
            for (int i = 0; i < roomUserList.size(); i++) {
                if (StrUtil.isEmpty(roomUserList.get(i).getUserName())) {
                    roomUserList.get(i).setUserName(Room.ROMM_TYEP_MAP.get(roomUserList.get(i).getRoomUser() + roomNumber));
                }
            }
        }

        for (int i = 0; i < totalUserList.size(); i++) {
            if (StrUtil.isEmpty(totalUserList.get(i).getUserName())) {
                totalUserList.get(i).setUserName(Room.ROMM_TYEP_MAP.get(totalUserList.get(i).getRoomUser() + roomNumber));
            }

        }
        if (roomUserList.size() > 0) {
            map.put("gameCount", gameCount);
            map.put("gameCost", yjRoomUser);
            map.put("success", true);
            map.put("user", roomUserList);
        } else {
            map.put("success", false);
            map.put("list", gameCountList);
        }
        return map;
    }


    @RequestMapping("/findByPage")
    @ResponseBody
    public Map<String, Object> findByPage(String pageSize, String pageNo) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<YJRoomUser> pagedList = new ArrayList<>();
        //进行分页
        if (pageList.size() > 0) {
            ListPageUtil<YJRoomUser> listPageUtil = new ListPageUtil<YJRoomUser>(pageList, Integer.valueOf(pageNo), Integer.valueOf(pageSize));
            pagedList = listPageUtil.getPagedList();
        }
        map.put("scoreList", pagedList);
        map.put("success", true);
        return map;
    }

    /**
     * 帮记
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/helpNotes")
    public AjaxJson helpNotes(String openId, HttpServletRequest request) {
        AjaxJson ajaxJson = new AjaxJson();
        String roomFlag = request.getParameter("roomFlag");
        if (StringUtils.isBlank(roomFlag)) {
            ajaxJson.setSuccess(false);
            ajaxJson.setErrorCode("0");
            ajaxJson.setMsg("房间为空");
            return ajaxJson;
        }
        List<YsUser> ysUsers = yjRoomUserMapper.findUserInfoByRoomFlag(roomFlag);
        if (ysUsers != null && !ysUsers.isEmpty()) {
            ysUsers = ysUsers.stream().filter(v1 -> !openId.equals(v1.getOpenid())).collect(Collectors.toList());
        }
        ajaxJson.setSuccess(true);
        ajaxJson.setMsg("查询成功");
        final LinkedHashMap<String, Object> linkedHashMap = Maps.newLinkedHashMap();
        linkedHashMap.put("users", ysUsers);
        ajaxJson.setBody(linkedHashMap);
        return ajaxJson;
    }
}
